<?php

namespace Modules\Admin\Http\Controllers\Components;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;

class ListsController extends Controller
{
    /**
     * Display a listing of the resource.
     */
    public function index()
    {
        $moduleStatuses = json_decode(file_get_contents(base_path('modules_statuses.json')), true);
        $enabledModules = array_filter($moduleStatuses, function($enabled) {
            return $enabled === true;
        });
                            
        // 获取模块详细信息
        $modulesInfo = [];
        foreach(array_keys($enabledModules) as $moduleName) {
            $modulePath = base_path('Modules/' . $moduleName);
            $moduleJsonPath = $modulePath . '/module.json';
                                
            if (file_exists($moduleJsonPath)) {
                $moduleData = json_decode(file_get_contents($moduleJsonPath), true);
                $modulesInfo[$moduleName] = $moduleData;
            }
        }

        return view('admin::components.lists.index', compact('modulesInfo'));
    }
}
